package com.yyplatform.admin.platform.init.data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.yyplatform.admin.platform.role.controller.SysDeptController;
import com.yyplatform.admin.platform.role.controller.SysPostController;
import com.yyplatform.admin.platform.role.controller.SysRoleController;
import com.yyplatform.admin.platform.role.controller.SysUserController;
import com.yyplatform.admin.platform.role.controller.SysUserTokenController;
import com.yyplatform.admin.platform.role.model.entity.SysMenuEntity;
import com.yyplatform.admin.platform.role.model.enums.MenuTypeEnum;
import com.yyplatform.admin.platform.role.repository.SysMenuRepository;
import com.yyplatform.admin.platform.role.service.SysMenuService;

/**
 * @author sleepforests@163.com
 * <p>
 * Created on 2024/11/16 20:42
 */

public class InitMenuData1Role {

    private SysMenuRepository sysMenuRepository;

    private SysMenuService sysMenuService;


    public InitMenuData1Role(SysMenuRepository sysMenuRepository, SysMenuService sysMenuService) {
        this.sysMenuRepository = sysMenuRepository;
        this.sysMenuService = sysMenuService;
    }


    public void init() {
        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(true);
        menu.setComponent("Layout");
        menu.setEnabled(true);
        menu.setIcon("role");
        menu.setKeepAlive(true);
        menu.setName("权限管理");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("");
        menu.setPid(0L);
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("");
        menu.setRoutePath("/role");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_FOLDER.getValue());

        sysMenuRepository.save(menu);


        test_init_系统管理_用户管理(menu);
        test_init_系统管理_角色管理(menu);
        test_init_系统管理_部门管理(menu);
        test_init_系统管理_岗位管理(menu);
        test_init_系统工具_在线用户(menu);

    }

    public void test_init_系统管理_用户管理(SysMenuEntity rootMenu) {
        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/user/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-Avatar");
        menu.setKeepAlive(true);
        menu.setName("用户管理");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:user:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("User");
        menu.setRoutePath("platform/user/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        Long id = menu.getId();
        sysMenuService.saveBatchByControllerName(id, SysUserController.class.getName());
    }


    public void test_init_系统管理_角色管理(SysMenuEntity rootMenu) {
        long id = 0;
        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/role/index");
        menu.setEnabled(true);
        menu.setIcon("role");
        menu.setKeepAlive(true);
        menu.setName("角色管理");
        menu.setOrderNum(200);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:role:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("Role");
        menu.setRoutePath("platform/role/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        sysMenuService.saveBatchByControllerName(id, SysRoleController.class.getName());
    }


    public void test_init_系统管理_部门管理(SysMenuEntity rootMenu) {


        long id = 0;


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/dept/index");
        menu.setEnabled(true);
        menu.setIcon("tree");
        menu.setKeepAlive(true);
        menu.setName("部门管理");
        menu.setOrderNum(200);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:dept:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("Dept");
        menu.setRoutePath("platform/dept/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        sysMenuService.saveBatchByControllerName(id, SysDeptController.class.getName());
    }

    public void test_init_系统管理_岗位管理(SysMenuEntity rootMenu) {


        long id = 0;

        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/post/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-Platform");
        menu.setKeepAlive(true);
        menu.setName("岗位管理");
        menu.setOrderNum(200);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:post:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("Post");
        menu.setRoutePath("platform/post/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        sysMenuService.saveBatchByControllerName(id, SysPostController.class.getName());
    }


    public void test_init_系统工具_在线用户(SysMenuEntity rootMenu) {


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/userToken/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-User");
        menu.setKeepAlive(true);
        menu.setName("在线用户");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:userToken:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("UserToken");
        menu.setRoutePath("platform/userToken/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        Long id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(SysUserTokenController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);

    }


}
